package com.service.impl;

import com.dao.RbacManagerDao;
import com.entity.RbacManager;
import com.entity.ResponseEntity;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.service.RbacManagerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class RbacManagerServiceImpl implements RbacManagerService {
    @Autowired
    RbacManagerDao rbacManagerDao;
    @Override
    public ResponseEntity addOne(RbacManager rbacManager) {
        int i = rbacManagerDao.addOne(rbacManager);
        if(i > 0){
            return ResponseEntity.SUCCESS;
        }else {
            return ResponseEntity.FAIL;
        }
    }

    @Override
    public ResponseEntity deleteOne(int id) {
        int i = rbacManagerDao.deleteOne(id);
        if(i > 0){
            return ResponseEntity.SUCCESS;
        }else {
            return ResponseEntity.FAIL;
        }
    }

    @Override
    public ResponseEntity updateOne(RbacManager rbacManager) {
        int i =  rbacManagerDao.updateOne(rbacManager);
        System.out.println("i = " + i);
        if(i > 0){
            return ResponseEntity.SUCCESS;
        }else {
            return ResponseEntity.FAIL;
        }
    }

    @Override
    public ResponseEntity findOne(int id) {
        RbacManager one = rbacManagerDao.findOne(id);
        return new ResponseEntity(200,"成功", one);
    }

    @Override
    public ResponseEntity findAll(int startPage,int pageSize) {
        PageHelper.startPage(startPage, pageSize);
        List<RbacManager> all = rbacManagerDao.findAll();
        return new ResponseEntity(200,"成功",all);
    }

    @Override
    public ResponseEntity findByName(int startPage,int pageSize,String account) {
        PageHelper.startPage(startPage, pageSize);
        List<RbacManager> all = rbacManagerDao.findByName(account);
        return new ResponseEntity(200,"成功",all);
    }
}
